package com.example.chatchatbackend.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.Sensitivewords;
import com.example.chatchatbackend.entity.vo.response.SensitivewordsVO;
import com.example.chatchatbackend.service.SensitivewordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */

@Slf4j
@RestController
@RequestMapping("/api/sensitivewords")
public class SensitivewordsController {

    @Autowired
    private SensitivewordsService sensitivewordsService;

    @GetMapping
    public RestBean<List<SensitivewordsVO>> getAllComment(){
        return RestBean.success(sensitivewordsService.getAllSensitivewords());
    }

    @PostMapping
    public RestBean<SensitivewordsVO> insertAdv(@RequestBody SensitivewordsVO sensitivewordsVO){
        SensitivewordsVO insertSensitivewordsVO = sensitivewordsService.insertSensitivewords(sensitivewordsVO);
        return RestBean.success(insertSensitivewordsVO);

    }

    @PostMapping("/list")
    public RestBean<List<SensitivewordsVO>> insertAdvList (@RequestBody List<SensitivewordsVO> sensitivewordsVO){
        List<SensitivewordsVO> SensitivewordsList = sensitivewordsService.insertSensitivewordsList(sensitivewordsVO);
        return RestBean.success(SensitivewordsList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<Sensitivewords>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(sensitivewordsService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<SensitivewordsVO> updateSensitivewords(@RequestBody SensitivewordsVO sensitivewordsVO){
        return RestBean.success(sensitivewordsService.updateSensitivewords(sensitivewordsVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        sensitivewordsService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }

    @GetMapping("/ids")
    public RestBean<List<SensitivewordsVO>> findByIds(@RequestBody List<Integer> ids){
        List<SensitivewordsVO> sensitivewordsVOList = sensitivewordsService.findByIds(ids);
        return RestBean.success(sensitivewordsVOList);
    }

    @GetMapping("/words/ids")
    public RestBean<List<SensitivewordsVO>> autoSendMessage(@RequestParam List<Integer> ids){
        return RestBean.success();
    }

}
